//package com.xzs.jersey.resource;
//
//import com.xzs.jersey.util.HttpUtil;
//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;
//import org.springframework.stereotype.Component;
//
//import javax.net.ssl.HttpsURLConnection;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.ws.rs.Consumes;
//import javax.ws.rs.GET;
//import javax.ws.rs.Path;
//import javax.ws.rs.core.Context;
//import javax.ws.rs.core.MediaType;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.net.URL;
//
//@Component
//@Path("/music")
//public class music163 {
//
//
//    /**
//     * music 下载链接获取
//     *
//     * @throws Exception
//     */
//    @GET
//    @Path("/down")
//    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
//    public void getOneURL(@Context HttpServletRequest request, String id,
////                          @Context HttpServletResponse response) throws Exception {
////        String musicListURL = "https://api.imjad.cn/cloudmusic/?type=playlist&${id}";
////        musicListURL = musicListURL.replace("${id}", id);
////
////        JSONObject musics = HttpUtil.httpsRequest(musicListURL, "GET", null);
////        JSONObject musicList = (JSONObject) musics.get("playlist");
////        JSONArray ids = musicList.getJSONArray("tracks");
////        for (int i = 0; i < ids.size(); i++) {
////            JSONObject music = ids.getJSONObject(i);
////            String name = music.getString("name");
////            String musicId = music.getString("id");
////            String getDownURl = "https://api.imjad.cn/cloudmusic/?type=song&id=${musicID}&br=320000";
////            getDownURl = getDownURl.replace("${musicID}", musicId);
////            JSONObject musicsDownUrls = HttpUtil.httpsRequest(getDownURl, "GET", null);
////            JSONArray urls = musicsDownUrls.getJSONArray("data");
////            String musicsDownUrl = urls.getJSONObject(0).getString("url");
////            try {
////                URL url = new URL(musicsDownUrl);
////                HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
////                httpUrlConn.setDoOutput(true);
////                httpUrlConn.setDoInput(true);
////                httpUrlConn.setUseCaches(false);
////                // 设置请求方式（GET/POST）
////                httpUrlConn.setRequestMethod("GET");
////                // 将返回的输入流转换成字符串
////                InputStream inputStream = httpUrlConn.getInputStream();
////                File file = new File("/Users/xuzs/Desktop/music/" + name + ".mp3");
////                FileOutputStream fos = new FileOutputStream(file);
////                byte[] b = new byte[1024];
////                int nRead = 0;
////                while ((nRead = inputStream.read(b)) != -1) {
////                    fos.write(b, 0, nRead);
////                }
////                fos.flush();
////                fos.close();
////                inputStream.close();
////                httpUrlConn.disconnect();
////            } catch (IOException ioe) {
////                ioe.printStackTrace();
////            } finally {
////
////            }
////        }
////    }
//}